<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>商品二级菜单（点击）</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }

    ul {
      list-style: none;
    }

    .shop {
      width: 1000px;
      height: 500px;
      background-color: #eee;
      margin: 0 auto;
      margin-top: 200px;
    }

    .left {
      float: left;
    }

    .shop .left {
      width: 250px;
      height: 100%;
      background-color: orange;
    }

    .left-title li {
      height: 50px;
      width: 250px;
      text-align: center;
      background-color: #eee;
      padding-top: 14px;
      border: 1px solid orange;
      cursor: pointer;
    }

    .right {
      float: right;
    }

    .right .right-title li {
      width: 750px;
      height: 500px;
      border: 1px solid orange;
      display: none;
      background-color: #eee;
      border-left: none;
      text-align: center;
      font-size: 36px;
    }

    .left-title .on {
      border-right: none;
    }

    .right .right-title .activate {
      display: block;
    }
  </style>
</head>

<body>
  <div class="shop">
    <div class="left">
      <ul class="left-title">
        <li class="on">商品1</li>
        <li>商品2</li>
        <li>商品3</li>
        <li>商品4</li>
      </ul>
    </div>
    <div class="right">
      <ul class="right-title">
        <li class="activate">内容1</li>
        <li>内容2</li>
        <li>内容3</li>
        <li>内容4</li>
      </ul>
    </div>
  </div>
  <script>
    // 获取元素
    let menus = document.querySelectorAll(".left-title li");
    let contents = document.querySelectorAll(".right-title li");
    // 点击菜单栏，显示对应的内容
    menus.forEach(function (menu, index) {
      menu.addEventListener("click", function () {
        menus.forEach(function (item) {
          item.classList.remove("on")
        })
        this.classList.add("on");

        contents.forEach(function (i) {
          i.classList.remove("activate");
        })
        contents[index].classList.add("activate");
      })
    })
  </script>
</body>

</html>